package reverse_linkedlist

import (
	"algorithm/src/utils"
)

//ReverseLinkedList Reversed a linkedlist
func ReverseLinkedList(l *utils.ListNode) *utils.ListNode {
	if l == nil || l.Next ==  nil {
		return l
	}
	node := ReverseLinkedList(l.Next)
	l.Next.Next = l
	l.Next = nil
	return node
}

func makeLinkedList(nums []int) *utils.ListNode {
	if len(nums) == 0 {
		return nil
	}
	head := &utils.ListNode{}
	cur := head
	for _, v := range nums {
		cur.Next = &utils.ListNode{
			Val: v,
		}
		cur = cur.Next
	}
	head = head.Next
	return head
}